/* 
 * File:   FPNode.h
 * Author: wx
 *树节点
 * Created on 2009年12月20日, 下午3:50
 */

#ifndef _FPNODE_H
#define	_FPNODE_H

#include <vector>
#include <map>
using namespace std;

class FPNode
{
private:
    int item;
    int count;
    FPNode * next;
    FPNode * parent;
    vector<int> childset;
    map<int,FPNode *> childmap;
public:
    FPNode(int id)
    {
        item = id;
        count = 1;
        next = NULL;
        parent = NULL;
    }

    FPNode(const FPNode& fp)
    {
        item = -1;
        count = 0;
        next = NULL;
        parent = NULL;
        childset = fp.childset;
        childmap = fp.childmap;
    }

    int getItem()
    {
        return item;
    }

    FPNode * getNext()
    {
        return next;
    }

    FPNode * getParent()
    {
        
    }

    void setNext(FPNode * fp)
    {
        next = fp;
    }

    int getCount()
    {
        return count;
    }

    int getChildCount()
    {
        return childset.size();
    }

    bool haschild(int k)
    {
        for( int i = 0;i < childset.size();i++)
        {
            if( childset[i] == k)
                return true;
        }
        return false;
    }

    FPNode * getChildNode(int k)
    {
        return childmap[k];
    }

    FPNode * getSingleNode()
    {
        return childmap.begin()->second;
    }

    void increaseone()
    {
        count++;
    }

    FPNode * createChildNode(int k)
    {
        childset.push_back(k);
        childmap[k] = new FPNode(k);
        childmap[k]->parent = this;
        return childmap[k];
    }

    void clearChild()
    {
        childset.clear();
        childmap.clear();
    }

    vector<FPNode *> getAllChild()
    {
        vector<FPNode *> result;
        for(map<int,FPNode*>::iterator mi = childmap.begin();mi != childmap.end();mi++)
        {
            result.push_back(mi->second);
        }
        return result;
    }
};

#endif	/* _FPNODE_H */

